#pragma once

#include <unistd.h>
#include <string>
#include <sys/stat.h>

namespace sca {

    /**
     * Determine whether the file exists
     * @param filePath
     * @return if the file exists,return true, otherwise, return false
     */
    static bool isFileExist(const std::string &filePath) {
        if (!access(filePath.c_str(), F_OK)) {
            return true;
        }
        return false;
    }

    /**
     * create a specific directory
     * @param dirPath
     */
    static void createFileDir(const std::string &dirPath) {
        if (!isFileExist(dirPath)) {
            std::string command = "mkdir " + dirPath;
            system(command.c_str());
        }
    }

    /**
     * delete the directory
     * @param dirPath
     */
    static void deleteDir(const std::string &dirPath) {
        if (isFileExist(dirPath)) {
            std::string command = "rm -rf  " + dirPath;
            system(command.c_str());
        }
    }

    /**
     * 生成临时的汇编文件
     * @param targetPath 被测的目标文件路径
     */
    static void generateDisassemblyFile(const std::string &targetPath, const std::string &tempFileDir) {
        deleteDir(tempFileDir);
        createFileDir(tempFileDir);
        std::string command = "objdump -j .text -S " + targetPath + "> " + tempFileDir + "/bin.S";
        system(command.c_str());
    }
}